package com.yt.bigdata;

import com.y.report.hepler.DbHelper;
import com.y.report.hepler.ResultSetUtil;

import java.time.Duration;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JDBCtest {
    //distinct
    private static String sql = "select\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`customer_identifier` `dm_fbu_customer_income_group_inc_d_des.customer_identifier`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`customer_type` `dm_fbu_customer_income_group_inc_d_des.customer_type`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`customer_sub_type` `dm_fbu_customer_income_group_inc_d_des.customer_sub_type`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`sign_body_name` `dm_fbu_customer_income_group_inc_d_des.sign_body_name`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`service_body_name` `dm_fbu_customer_income_group_inc_d_des.service_body_name`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`region` `dm_fbu_customer_income_group_inc_d_des.region`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`regional_name` `dm_fbu_customer_income_group_inc_d_des.regional_name`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`mapp` `dm_fbu_customer_income_group_inc_d_des.mapp`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`fee_type_first_name` `dm_fbu_customer_income_group_inc_d_des.fee_type_first_name`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`business_type` `dm_fbu_customer_income_group_inc_d_des.business_type`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`customer_code` `dm_fbu_customer_income_group_inc_d_des.customer_code`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`account_code` `dm_fbu_customer_income_group_inc_d_des.account_code`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`data_source` `dm_fbu_customer_income_group_inc_d_des.data_source`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`regional_warehouse_name` `dm_fbu_customer_income_group_inc_d_des.regional_warehouse_name`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`physical_warehouse_name` `dm_fbu_customer_income_group_inc_d_des.physical_warehouse_name`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`physical_warehouse_code` `dm_fbu_customer_income_group_inc_d_des.physical_warehouse_code`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`types_of_fee_name` `dm_fbu_customer_income_group_inc_d_des.types_of_fee_name`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`currency_code` `dm_fbu_customer_income_group_inc_d_des.currency_code`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`amount_after_rebate` `dm_fbu_customer_income_group_inc_d_des.amount_after_rebate`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`local_currency_amount` `dm_fbu_customer_income_group_inc_d_des.local_currency_amount`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`manage_report_time_month` `dm_fbu_customer_income_group_inc_d_des.manage_report_time_month`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`manage_report_time` `dm_fbu_customer_income_group_inc_d_des.manage_report_time`,\n" +
            "        dm_fbu_customer_income_group_inc_d_des.`__ETL_INSERT_TIME__` `dm_fbu_customer_income_group_inc_d_des.__ETL_INSERT_TIME__`\n" +
            "from\n" +
            "        data_load.limit_loushu_bug  as dm_fbu_customer_income_group_inc_d_des\n" +
            "where\n" +
            "        ( dm_fbu_customer_income_group_inc_d_des.`customer_identifier` = '正式客户' )\n" +
            "        and ( (dm_fbu_customer_income_group_inc_d_des.`manage_report_time` >= '2022-01-01 00:00:00'\n" +
            "                and dm_fbu_customer_income_group_inc_d_des.`manage_report_time` <= '2022-12-31 23:59:59') )\n" +
            "        and ( dm_fbu_customer_income_group_inc_d_des.`fee_type_first_name` IN ( '其他赔付', '货值赔偿' ) ) \n" +
            "limit 10000";

    public static void main(String[] args) {
        String url = "jdbc:mysql://10.192.112.28:3306?serverTimezone=UTC";
        String username = "dlink";
        String pass = "P2_s1sw0rd";
        String driver = "com.mysql.cj.jdbc.Driver";
        Map<String, String> props = new HashMap<>();
        props.put("driverClassName", driver);
        props.put("jdbcUrl", url);
        props.put("username", username);
        props.put("password", pass);

        DbHelper dbHelper = new DbHelper(props);

        Instant starTs = Instant.now();
        List<Map<String, Object>> result = dbHelper.query("select now()", null);
        System.err.println(result);
        Instant endTs = Instant.now();
        Duration duration = Duration.between(starTs, endTs);

        System.out.println(String.format("耗时:%s, 总数:%s", String.format("%s hour,%s min, %s s", duration.toHours(), duration.toMinutes() % 60, duration.getSeconds() % 60), result.size()));


    }


}
